<%@ page contentType="text/html;charset=UTF-8" import="java.util.*,java.sql.*" language="java" %>
<%
    String username = "usr_mh"; //数据库用户名
    String password = "apexsoft"; //数据库密码
    String url = "jdbc:oracle:thin:@115.29.140.182:1521:apexsoft"; //数据库url
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(url, username, password);

    ResultSet rs = null;
    PreparedStatement pstmt = null;
    List<Object[]> list = new ArrayList<Object[]>();
    String postr = request.getParameter("po");
    postr = (postr == null || "".equals(postr)) ? "1" : postr;
    int po = Integer.parseInt(postr); //当前页码
    int ep = 15; //每页条数
    try {
        String sql = "select userid,name from tuser order by userid";
        int startInt = (po - 1) * ep;
        int endInt = ep * po;
        sql = "SELECT * FROM (SELECT ROW_.*,ROWNUM RN FROM ( " + sql + ") ROW_ ) WHERE RN > " + startInt + " AND RN <= " + endInt;
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            list.add(new Object[]{rs.getObject(1), rs.getObject(2)});
        }
    } catch (Exception e) {
    } finally {
        try {
            if (rs != null) rs.close();
        } catch (Exception e) {
        }
        try {
            if (pstmt != null) pstmt.close();
        } catch (Exception e) {
        }
        try {
            if (conn != null) conn.close();
        } catch (Exception e) {
        }
    }
%>
<html>
<head>
    <title></title>
</head>
<body>
<style>
    table{width: 200px;text-align: center;margin: 0 auto;border-collapse: collapse;}
    table th,table td{height: 30px;line-height: 30px;border: 1px solid #ccc;}
    a{text-decoration: none;color:blue;margin: 0 20px;}
</style>
<table>
    <tr>
        <th style="width: 45%;">用户账号</th>
        <th style="width: 55%">用户名</th>
    </tr>
    <%for (Object[] objs : list) {%>
    <tr>
        <td><%=objs[0]%>
        </td>
        <td><%=objs[1]%>
        </td>
    </tr>
    <%}%>
</table>
<%%>
<div style="text-align: center;margin: 0 auto;"><%if (po != 1) {%><a href="a.jsp?po=<%=po-1%>">上一页</a><%}%>当前页数：<%=po%>
    <a href="a.jsp?po=<%=po+1%>">下一页</a>
</div>
</body>
</html>
